How to convert [object Object],[object Object] to [Object, Object] in javascript? -
was trying send static data websocket , receive same. data is
var details= [ { "_id": "5799fac61ee480492224071a", "index": 0, "age": 25, "name": "jean pierce", "gender": "female", "email": "jeanpierce@cincyr.com" }, { "_id": "5799fac678aae9a71af63ef2", "index": 1, "age": 23, "name": "laurie lopez", "gender": "female", "email": "laurielopez@cincyr.com" }, { "_id": "5799fac6c237d929693c08d7", "index": 2, "age": 21, "name": "padilla barrett", "gender": "male", "email": "padillabarrett@cincyr.com" } ];
when above data received, in form of string, parsed json using json.parse(data)
, store in local variable. now, issue here is, parsing, need converted [object,object]
form instead of [object object],[object object]
coming on console. how achieve ?
update: code same below, please have check.
sending data websocket server using below code
if (client.readystate === client.open) { client.send(json.stringify(details)); }
on receiving end data received -
client.onmessage = function(e) { console.log(" fetched data :"+json.parse(e.data)); this.setstate({ val: json.parse(e.data) }); }.bind(this);
the console.log()
in second statement showing result [object object],[object object]
parsing same in react [ object object]
needed. how achieve ?
here go:
console.log('[' + array.fill('object').tostring() + ']')
test:
var array = [ { "_id": "5799fac61ee480492224071a", "index": 0, "age": 25, "name": "jean pierce", "gender": "female", "email": "jeanpierce@cincyr.com" }, { "_id": "5799fac678aae9a71af63ef2", "index": 1, "age": 23, "name": "laurie lopez", "gender": "female", "email": "laurielopez@cincyr.com" }, { "_id": "5799fac6c237d929693c08d7", "index": 2, "age": 21, "name": "padilla barrett", "gender": "male", "email": "padillabarrett@cincyr.com" } ] console.log('[' + array.fill('object').tostring() + ']')
though don't know why you'd want on other - both equally (un)helpful. sure don't want console.dir
?
Comments
Post a Comment