1

Before my Ajax function is called, I have a global scoped names array like this:

var names =  ["John Smith","Mike Jones","Jenny White","April Brown"];

In the success function of the ajax call I need to erase the array and repopulate it with new names passed back to the page in Json format (v.name in the example below).

But I'm not sure how to append to the array in the course of my $.each loop:

$.each(data, function() {
  $.each(this, function(k, v) {

      // how to add `v.name` to the `names` array?

  });
});

1 Answer 1

5

Assuming you have already cleared names, try this:

$.each(data, function() {
  $.each(this, function(k, v) {
      names.push(v.name);
  });
});
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.