1

I its basic but I am new to javascript. I am trying to loop through the array and match the objects that == my key.

this is what i am using right now, it works but i am only matching the first object that matches, sometimes there will be multiple objects that match.

Here is what i have now

var chartSeries = chartService.getSeries();
var marker.options.subdivision.id = 1345
var matchingSeries = Enumerable.From(chartSeries).Where('x => x.id == "' + marker.options.subdivision.id + '"').ToArray();
   var series = {
        id: matchingSeries[0].id,
        name: matchingSeries[0].name,
        data: matchingSeries[0].data,
        lineWidth: 5
    };

I need to include a for loop to match all objects.

    var subIdSeries = [];
    var subId = marker.options.subdivision.id;
    var series = {
        id: matchingSeries[0].id,
        name: matchingSeries[0].name,
        data: matchingSeries[0].data,
        lineWidth: 5
    };

    for (var i = 0; i < chartSeries.length; i++) {

        if (subId == chartSeries.id) {
            push.subIdSeries(subId)
        }
    }
2
  • Should it be subIdSeries.push(subId) instead of push.subIdSeries(subId)? Commented Apr 9, 2015 at 15:26
  • you can use Array.map or Array.forEach or Array.filter Commented Apr 9, 2015 at 15:28

2 Answers 2

3

Change

if (subId == chartSeries.id) {
    push.subIdSeries(subId)
}

to

if (subId == chartSeries[i].id) {
    subIdSeries.push(subId)
}
Sign up to request clarification or add additional context in comments.

Comments

2

Without seeing the whole script, from what you have so far, I can suggest:

if (subId == chartSeries[i].id) {
    subIdSeries.push(subId)
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.