Return key and value in a Javascript object -
how go returning key , value string or smaller object:
var whatisinaname = [{ a: "a1", b: "b1" },{ a: "c1", b: "d1" },{ a: "e1", b: "f1" }]; returning like: "a:a1"
i know object.values , object.keys. combination of this?
if interpret question correctly, can use array.prototype.map(), json.stringify(), string.prototype.replace() regexp /[{}]/g , replacement string "", array.prototype.join() parameter ","
var arr = [{ a: "a1", b: "b1" },{ a: "c1", b: "d1" },{ a: "e1", b: "f1" }]; var res = arr.map(obj => json.stringify(obj).replace(/[{}]/g,"")); console.log(res.join(","))
Comments
Post a Comment