Parse Nested Array

Pavan_Snow_1
Kilo Guru

Hi all,

I am storing the Array in below format. I need Line Id value from each object.

[

{'Quantity': '4','Parent':'OR00001','Sku':'Test1','Line Id':'3.00'},

{'Quantity': '5','Parent': 'OR00001','Sku': 'Test2','Line Id': '2.00'}

]

please help how to get the Line Id details from above array.

Thanks,

Pavan

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this works well

var obj = [
{'Quantity': '4','Parent':'OR00001','Sku':'Test1','Line Id':'3.00'},
{'Quantity': '5','Parent': 'OR00001','Sku': 'Test2','Line Id': '2.00'}
];

var arr = [];

for(var i=0;i<obj.length;i++)
arr.push(obj[i]['Line Id'].toString());

gs.info(arr);

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this works well

var obj = [
{'Quantity': '4','Parent':'OR00001','Sku':'Test1','Line Id':'3.00'},
{'Quantity': '5','Parent': 'OR00001','Sku': 'Test2','Line Id': '2.00'}
];

var arr = [];

for(var i=0;i<obj.length;i++)
arr.push(obj[i]['Line Id'].toString());

gs.info(arr);

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Allen Andreas
Administrator
Administrator

Hi,

You can try this in background to see if you like it:

var array = [

{'Quantity': '4','Parent':'OR00001','Sku':'Test1','Line Id':'3.00'},

{'Quantity': '5','Parent': 'OR00001','Sku': 'Test2','Line Id': '2.00'}

];

for (var i=0;i<array.length;i++) {
gs.info(array[i]['Line Id']);
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!