then
убирали? var arr = [
{
name: 'Alex',
data: {
role: '1'
},
childItems: ['Bob', 'Alice']
},
{
name: 'Kristine',
data: {
role: '2'
},
childItems: ['Kate', 'Morgan']
}
];
function copy(object) {
var root = {};
Object.keys(object).forEach(function (key) {
var branch = object[key];
if (typeof branch === 'object' && !(branch instanceof Array)) {
root[key] = copy(branch);
} else {
root[key] = branch;
}
});
return root;
}
var newArr = arr.reduce(function (acc, entry) {
var clonedEntry = copy(entry);
delete(clonedEntry.childItems);
acc.push(clonedEntry);
return acc;
}, []);
console.log(arr); // [{ name: 'Alex', data: { role: '1' }, childItems: [ 'Bob', 'Alice' ] }, { name: 'Kristine', data: { role: '2' }, childItems: [ 'Kate', 'Morgan' ] }]
console.log(newArr); // [{ name: 'Alex', data: { role: '1' } }, { name: 'Kristine', data: { role: '2' } }]
copy
сделать для разных типов. [
{
"name": " Some text ",
"option": 1
},
{
"name": " Some text 2",
"option": 4
},
{
"name": " Some text - also text",
"option": 0
},
{
"name": " Text\" Textי\" Text",
"option": 6
},
{
"name": " Text / Text(text)",
"option": 7
}
]
textContent
вообще