Format Json String with JSON.stringify(out, null, 2) - Javascript JSon

Javascript examples for JSon:JSon String

Description

Format Json String with JSON.stringify(out, null, 2)

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*ww  w .  jav  a  2 s .  co m*/

var arr = [4, 1, 2, 3, 4];
const out = arr.reduce((p, c) => {
  c % 2 === 0 ? p.unshift(c) : p.push(c)
  return p;
}, []);
console.log(JSON.stringify(out, null, 2));


    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials