Why an array (array) missing values?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
30 views
var list_items = [ 0, { id_item: 1, name_item: 'CD Antler (008)', title_item: 'ompact Antler will fit into any interior thanks to its forms.', atricle_item: 'DE611090008', search_key_item: 'antler antler compact compact (008) 008 DE611090008 611090008', price_item: '9330', collection_item: 'Antler', type_item: 'unitaz', }, 1, { id_item: 2, name_item: 'CD Boston OAK (024)', title_item: 'ompact Antler will fit into any interior thanks to its forms.', atricle_item: 'DE611090008', search_key_item: 'boston compact the Boston compact (024) 024 DE721090024 721090024', price_item: '12333', collection_item: 'Boston', type_item: 'unitaz', } ]; console.log('list_items[0]' + list_items[0].name_item); console.log('list_items[1]' + list_items[1].name_item); console.log('list_items[2]' + list_items[2].name_item); console.log('list_items[3]' + list_items[3].name_item);


Why it fails with the following:
list_items[0]undefined
list_items[1]CD Antler (008)
list_items[2]undefined
list_items[3]CD Boston OAK (024)


Can't understand why it skips 0 and 2, please help! Maybe I something doing wrong?
by | 30 views

3 Answers

0 like 0 dislike
You have zero element is the number 0. He does not have the key name_item
by
0 like 0 dislike
If understand correctly, You want to get the id of the key.
Then in the array remove the number 0 and 1 (from the example)
each object in the array will already have your id
to obtain such a second, use Object.keys
console.log(Object.keys(list_items)[1]);
by
0 like 0 dislike
And how to write correctly at all? any guides don't help( I'm stupid(.

var list_items = [{ id_item: 1, name_item: 'CD Antler (008)', atricle_item: 'DE611090008', price_item: '9330', }, { id_item: 2, name_item: 'CD Boston OAK (024)', atricle_item: 'DE611090008', price_item: '12333', } ];

ever) comes out)
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked May 22, 2019 by mrserg4102
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users