I am running node with cheerio. I have this function which needs to display an attribute value of an element contained in an array.
for (var row = 0; row < array.length; row++) {
console.log("Row Length: " + array[row].length);
for (var col = 0; col < array[row].length; col++) {
console.log("Inside:");
console.log(array[row][col].getAttribute('val'));
}
}
My array contains list items populated using push
array.push($('[title!="CATA"][collection="items"]'));
I get the desired output for 'Row Length', and it displays 'Inside', but then displays 'TypeError: undefined is not a function'. I have tried to use .attr('val') too but with the same error.
Executing console.log(array[row][col]) gives me the following.
{ type: 'tag',
name: 'li',
attribs:
{ id: 'Amber',
collection: 'items',
title: 'disk',
val: '10|9|2|10|7|13|2|10|12|2|2|5|3|3|5|2|8|7|5|10|4|6|6|3|4|6|2|8|11|2|10|7|9|9|10|8' },
children:
[ { data: 'disk : 10|9|2|10|7|13|2|10|12|2|2|5|3|3|5|2|8|7|5|10|4|6|6|3|4|6|2|8|11|2|10|7|9|9|10|8',
type: 'text',
next: null,
prev: null,
parent: [Circular] } ],
next:
{ type: 'tag',
name: 'li',
attribs:
{ id: 'Amber',
collection: 'items',
title: 'usb',
val: '3|3|2|4|2|4|3|3|3|13|5|13|2|13|2|5|5|3|4|3|6|3|2|2|5|13|2|3|2|13|2|13|2|2|13|4' },
children: [ [Object] ],
next:
.
.
.
All I am trying to do is to access the 'val'.