json stringify recursive
var test = { name: “John”, age: 21, scores: [89, 72, 96, 55, 66]}function type(obj) { return Object.prototype.toString.call(obj).match(/.* (.*)\]/)[ 1]}function stringify(obj) { if (type(obj) === “Function”) { return null } if (type(obj) === “Undefined”) { return null } if (type(obj) === “Null”) { return “null” } if (type(obj) === “Number”) { return obj } if (type(obj) === “String”) { return ‘”’ + obj + ‘”’ } if (type(obj) === “Array”) { return ‘[‘ + obj.map(function(o) { return stringify(o) }).join(“,”) + ‘]’ } if (type(obj) === “Object”) { var result = [] Object.keys(obj).forEach(function(key) { var val = stringify(obj[key]) if (val !== null) { result.push(‘”’ + key + ‘”: ‘ + val) } }) return “{“ + result.join(“,”) + “}” }}stringify(test) //==> {“name”: “John”,”age”: 21,”scores”: [89,72,96,55,66]}
Also in JavaScript:
- active-class router-link
- material css
- round to decimal javascript
- Too long with no output (exceeded 10m0s): context deadline exceeded
- react player disable download
- ways to show image in react native
- javascript check if is nan
- how to code a minecraft json file mod
- how to add data to array in javascript dynamically
- Unsupported engine { package: '[email protected]', required: { node: '~0.10' }, current: { node: 'v12.18.3', npm: '7.0.15' } }
- read image metadata javascript
- set stange beckground color easeljs
- Syntax Error: Thread Loader (Worker 0) .eslintrc.js: Environment key "es2021" is unknown at Array.forEach (<anonymous>)
- How can I display an image and text from an array on a webpage? Ask Question
- strapi cloudinary how to use
- geolocation speed
- get array by array of indices js
- npx react-native
- range javascript
- iterate over array javascript
- javascript get last n characters of string
- como percorrer um objeto js
- how to access data in firebase realtime
- add edit delete from table using jquery