Search code examples
javascriptarraysjsonobjectstringify

JSON.stringify("only values, not hash/key nor markup")


I have a obj -> JSON.stringify().

newString = '<pre>'+JSON.stringify(values, ['displayName'], 4)+'</pre>';

returns: enter image description here

I only want to show the values for the key "displayName" without any of the array/obj markyp("{}, [], etc") ---> Alexander Thorarinsson

Example of obj depths in 'values' array:

enter image description here

Log for every cell value for the given table render: enter image description here


Solution

  • You don't need stirngify, but you do need to unwrap the arrays carefully

    newString = '<pre>'+values[0].displayName[0]+'</pre>';