S
S
SvetlanaDubovik2017-05-31 09:43:37
JSON
SvetlanaDubovik, 2017-05-31 09:43:37

Can't write data to js array. What's wrong?

Hello. Tell me please. I have an array of objects.
Each object has the following structure:

activity = 
[ {
       '@attributes': {
               'Код': "1",
               Наим: "Текст"
        }
},
{
       '@attributes': {
               'Код': "2",
               Наим: "Текст"
        }
} 
и т.д. ]

I want to pull the code from each object and write to a new array. I want to do the same with the name.
var code = [],
      name = [];

for ( var i = 0; i < length; i ++) {
 code.push(activity[0][ '@attributes'][ 'Код']);
name.push(activity[0][ '@attributes'][ 'Наим']);
}

But the debugger complains that it doesn't know the @attributes property. It swears at the stage of writing the value to the array. When viewing data in the console, it displays correctly. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2017-05-31
@SvetlanaDubovik

Everything works fine prntscr.com/fe43sq
PS do not use Cyrillic in the keys

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question