object.flat code example
Example 1: js ,flat
const numbers = [1, 2, [3, 4, 5, [6, 7]]];
const flatNumbers = numbers.flat(2);
console.log(flatNumbers);
Example 2: javascript flat object
function dotify(obj) {
const res = {};
function recurse(obj, current) {
for (const key in obj) {
const value = obj[key];
if(value != undefined) {
const newKey = (current ? current + '.' + key : key);
if (value && typeof value === 'object') {
recurse(value, newKey);
} else {
res[newKey] = value;
}
}
}
}
recurse(obj);
return res;
}
dotify({'a':{'b1':{'c':1},'b2':{'c':1}}})
Example 3: js .flat
const arrays = [
["$6"],
["$12"],
["$25"],
["$25"],
["$18"],
["$22"],
["$10"]
];
const merge3 = arrays.flat(1);
console.log(merge3);