On the manipulation of objects in javascript
https://jsfiddle.net/20170808.
how can I output the following format:
/ / Wang Junkai Wang Yuan Yi Qianxi
/ / Jolin Tsai
/ / Gillian sa
var data = [
{
singer: [
{name: "",age: 18},
{name: "",age: 20},
{name: "",age: 18}]},
{
singer: [{name: "",age: 33}]},
{
singer: [
{name: "",age: 31},
{name: "Sa",age: 30}]
}]
data.forEach((item) => {
item.singer.forEach(v=>{
console.log(v.name)
})
});
//
//
//
//
//
//Sa
()
//
//
// Sa
var data = [
{
singer: [
{name: '',age: 18},
{name: '',age: 20},
{name: '',age: 18}]},
{
singer: [{name: '',age: 33}]},
{
singer: [
{name: '',age: 31},
{name: 'Sa',age: 30}]
}];
for(let i=0; i<data.length; iPP){
let arr = [];
data[i].singer.map((item)=>{
arr.push(item.name);
})
console.log(arr.join(' '))
}
copy it to the console and try it.
data.forEach( (dataItem,index)=>{
var str = ''
dataItem.singer.forEach( (singerItem,index)=>{
str += (singerItem.name + ',')
})
console.log(str.slice(0,str.length-1) )
})
data.forEach(o=>{
var name = o.singer.map(a=>a.name).join(" ")
console.log(name)
})
use babel to transfer
if compatible.
var data = [
{
singer: [
{name: '',age: 18},
{name: '',age: 20},
{name: '',age: 18}
]
},
{
singer: [{name: '',age: 33}]
},
{
singer: [
{name: '',age: 31},
{name: 'Sa',age: 30}]
}
]
data.forEach(obj => {
console.log(obj.singer.map(item => item.name).join(" "));
})