function jsonArrayTo2D(arrayOfObjects){
let header = [],
AoA = [];
arrayOfObjects.forEach(obj => {
Object.keys(obj).forEach(key => header.includes(key) || header.push(key))
let thisRow = new Array(header.length);
header.forEach((col, i) => thisRow[i] = obj[col] || '')
AoA.push(thisRow);
})
AoA.unshift(header);
return AoA;
}
var arr = [
["Status", "Name", "Marks", "Position"],
["active", "Akash", 10.0, "Web Developer"],
["active", "Vikash", 10.0, "Front-end-dev"],
["deactive", "Manish", 10.0, "designer"],
["active", "Kapil", 10.0, "JavaScript developer"],
["active", "Manoj", 10.0, "Angular developer"],
];
//javascript create JSON object from two dimensional Array
function arrayToJSONObject (arr){
//header
var keys = arr[0];
//vacate keys from main array
var newArr = arr.slice(1, arr.length);
var formatted = [],
data = newArr,
cols = keys,
l = cols.length;
for (var i=0; i<data.length; i++) {
var d = data[i],
o = {};
for (var j=0; j<l; j++)
o[cols[j]] = d[j];
formatted.push(o);
}
return formatted;
}
let thing = arrayToJSONObject(arr);
console.log(thing);
console.log(thing[0]['Name']);
/*Akash*/
const url = new URL('https://example.com/?firstkey=firstvalue&secondkey=secondvalue');
console.log(url.href);
// https://example.com/?a=hello&b=world
console.log(url.origin);
var obj = {};
for(const [key, value] of Array.from(url.searchParams.entries()))
{
obj[key] = value;
}
console.log(obj);
/*Object { firstkey: "firstvalue", secondkey: "secondvalue" }*/