0

I am going to create an array called idArray which contains Id of students in a csv file. inputData is an array containing 10 objects(records of csv). Each object is an array and have a "Unique Id". I would like to check if I already have this "Unique Id" in my idArray, if no, add it to the array and if yes go to the next record.

getIds: function (inputData) {
    inputData.forEach(function () {
        if(idArray.length!=0) {
            idArray.forEach(function () {
                if (inputData."Unique Id"!= idArray)
                    idArray.push(inputData."Unique Id");
            });
        }
        else
            idArray.push(inputData."Unique Id");
    });

  return idArray;
}

I know that inputData."Unique Id" is wrong, but how can I get Unique Id?

Thanks

Sana
  • 463
  • 2
  • 4
  • 22
  • @Bergi this isn't a duplicate of the suggested question... The issue isn't about how to access a property... – Matías Fidemraizer May 28 '15 at 13:57
  • @Bergi It's an issue in OP code, but the question ask for other thing too I was just to post when you closed the question – Matías Fidemraizer May 28 '15 at 13:58
  • @MatíasFidemraizer: A question should be asking for one thing only. What other issue do you see in the post? The only question I can read is "*`inputData."Unique Id"` is wrong, but how can I get Unique Id?*" - and that is sufficiently answered by the dupe. – Bergi May 28 '15 at 14:09
  • @Bergi For me, the main issue was how to check if unique id is in the array... btw I see OP has no criteria and has marked as answer the one published before you closed the Q&A.. – Matías Fidemraizer May 28 '15 at 14:18

1 Answers1

0

Try this

if (inputData["Unique Id"] != idArray)

If the attribute name doesn't have any spaces or special characters in it you can do

object.attributeName

Otherwise you need to reference it inside square brackets

object["attribute Name"]
Crwydryn
  • 840
  • 6
  • 13