1

My PHP file returned a JSON array full of values.

$positions = array();
while ($row = mysqli_fetch_assoc($abfrage)) {
    array_push(
        $positions,
        array(
            'posID' => $row['posID'],
            'pos1' => $row['pos1'],
            'pos2' => $row['pos2']
        )
    );
}

@mysql_close($connection);
echo json_encode(array("positions" => $positions));
exit; 

Now in my js-File, I want to delete a data set where posID == x for example, but I don't know how to do it

$.each(positions, function(i, v) {
  if (v.posID == id) {
    ... delete data set ...
  }
});

1 Answer 1

3

Create a new array with the items that you want to keep:

var result = $.grep(positions, function(v){
  return v.posID != id;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.