मान लीजिए, हमारे पास सरणियों की एक सरणी है जैसे −
const arr = [ [ ['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk'], [ ['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager'] ] ] ]; const convertToObject = (arr = []) => { const empty = {}; const res = arr.map(el => { const object = this; el.forEach(attr => { let name = attr[0], value = attr[1]; object[name] = value; return object; }, object); return this; }, empty); return res; } console.log(convertToObject(arr));आउटपुट
और कंसोल में आउटपुट होगा −
[ { firstName: 'Joe', lastName: 'Blow', age: 42, role: 'clerk', 'firstName,Mary': [ 'lastName', 'Jenkins' ] } ]