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}}}) //{'a.b1.c':1,'a.b2.c':1}
Also in JavaScript:
- nuxt error page
- react admin newrecords.foreach is not a function
- connect mongo to express api
- javascript get second last element in array
- javascript get element width and height
- refresh current component angular
- Material-ui wheelchair icon
- orm for postgres node js
- map a keys from an array in a separate arraylist javascript
- delete character between index
- mongodb replace document
- place white and black knights on 2x2 chessboard
- react native object is empty
- js remove background image
- News Application With Angular and Material Design
- javascript open link in new tab
- python object to json
- FizzBuzz
- onclick open link js
- express router middleware
- document getelementsbyclassname not getting all elements
- how to get user's machine and browser through js
- generate id js
- How many different types of JS alerts do we have?