what should I do now to get the name value inside?
what should I do now to get the name value inside?
first of all, your structure should be more appropriate as an array:
var data = [
{name: 'asdfadfa'},
{name: 'asdfadfa'},
{name: 'asdfadfa'},
{name: 'asdfadfa'},
{name: 'asdfadfa'},
{name: 'asdfadfa'}
];
then follow the structure you give, and traverse it like this:
for(let i in data) {
console.log(data[i].name);
}
if you change it to an array, traverse it like this:
for(let obj of data) {
console.log(obj.name);
}
for more group and object traversal methods, search for "js traversal array" and "js traversal object".
convert to an array with Object.keys
Object.keys(data).map(key => {
console.log(data.key.name);
})
using ES6 syntax, one line can be solved:
var data = {
1:{name: 'asdfadfa'},
2:{name: 'asdfadfa'},
3:{name: 'asdfadfa'},
4:{name: 'asdfadfa'},
5:{name: 'asdfadfa'},
6:{name: 'asdfadfa'}
}
Object.values(data).map(x => x.name)
although arrays should be used in this data structure, if you want to traverse such objects, you can use:
var data = {
0: {name: 'asdfadfa'},
1: {name:' asdfadfa'},
2: {name: 'asdfadfa'},
3: {name:' asdfadfa'},
4: {name: 'asdfadfa'},
5: {name:' asdfadfa'}
};
data.length = 6;
Array.prototype.slice.call (data) .map (val = > val.name)
var data = {
1 : {name: 'qweqweqwe'},
2 : {name: 'qweqweqwe'},
3 : {name: 'qweqweqwe'},
4 : {name: 'qweqweqwe'}
}
for(let i in data){
console.log(data[i].name)
}
The object.values method of es6, which is converted directly to an array
description: a regular match is given to the content of an input box, and the matching content is the product activation code. looks like this: "0C31-0B81-BB32-3094-0C31-0B81-BB32-3094 " Code: $( -sharplicenseCode ).keyup(function () { le...
recently I want to write a trial hand of a project with front and rear separation. since I have been self-taught nodejs, all this time, the idea is to build a back-end server with express framework, but in this way I don t know what to do in the middle...
because vue-router has "- sharp " by default, but when forwarding the address in Wechat s official account, the address "- sharp ", including all future addresses, will be removed directly, resulting in the inability to share the page. so I set the ...
when validating with jquery validate, using the valid () method will prompt all the form error messages. How to do form validation without displaying all failed messages when using the valid () method $("-sharpftpwd_tel...
customers are required to click the download button on the page to jump directly to the default browser instead of submitting and clicking the button in the upper right corner. I have also seen this practice, how can it be realized? ...
excuse me, now that we have done app on the web, we have encountered the problem of dropping the line behind the screen of the Android phone. I wonder if apicloud has a third-party service that can be pushed to the customer s notification bar even if th...
the two domain names doamin are different, is there any way to achieve cookie sharing? Boss solution ...
match `~! @-sharp$% ^ & * () _ +-= [] {} |;: ",. < >? these special symbols, how to write regular, always report errors. I don t know what needs to be escaped ....
I want to defend my login page against CSRF, but I don t know what to do now the page uses axios+ Tencent verification code (AJAX) ...
...