0

Given the array of object below:

function person(first, last, RPI, o, t, u) {
    this.first = first;
    this.last = last;
    this.RPI =  RPI;
    this.o = o;
    this.t = t;
    this.u = u;
}

var MD = new person('Mike', 'D', 1234, '', '', '');
var AY = new person('Adam', 'Y', 5678, '', '', '');
var AH = new person('Adam', 'H', 1212, '', '', '');

var personArray = new Array(MD, AY, AH);

How would I iterate the RPI value from each object into this formula?

function selector(x){
//do something with x.RPI
}

I've tried:

$.each(personArray , selector (personArray[person].RPI){
selector(x)
});

But it doesn't work. What am I doing wrong with my each statement?

3
  • personArray = {MD, AY, AHR, DD}; is not an array. Typo? Commented Jan 11, 2017 at 2:48
  • Yes. Typo. :-). Still the problem persisted. Commented Jan 11, 2017 at 2:50
  • Your use of each is wrong. The function is being called not referenced in the second argument. You have this weird {} after it.... Look at the documentation on how to use it api.jquery.com/jquery.each Commented Jan 11, 2017 at 2:52

2 Answers 2

1

The $.each callback needs to be a function Do something like the following:

var personArray = new Array (MW, MT, DR)
$.each(personArray, function(index, person){
   console.log(person.RPI);
}
Sign up to request clarification or add additional context in comments.

Comments

0

change your $.each to

$.each(personArray , selector);

and then

function selector(index, item){
    //do something with item.RPI
}

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.