JSON array in Node.js

后端 未结 3 1849
情书的邮戳
情书的邮戳 2021-01-17 05:06

I have been trying to figure this out for the past week and everything that i try just doesn\'t seem to work.

I have to create a web service on my local box that re

3条回答
  •  醉梦人生
    2021-01-17 05:29

    The replacer parameter of JSON.stringify doesn't work quite like you're using it; check out the documentation on MDN.

    You could use Array.prototype.filter to filter out the elements you don't want:

    var arr = [[],"d","B",{},"b",12,"A","c"];
    arr = arr.filter(function(v) { return typeof v == 'string'; });
    arr // => ["d", "B", "b", "A", "c"]
    

提交回复
热议问题