Advertisement
zingga

Abdul paste

Jun 23rd, 2021
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const _ = require('lodash')
  2.  
  3. const a = [
  4.   {
  5.     judul: "UUD 45",
  6.     no_uud: "123",
  7.     butir_1: "a. Hello World"
  8.   },
  9.   {
  10.     butir_1: "a. Hello World"
  11.   },
  12.   {
  13.     butir_1: "a. Hello World"
  14.   },
  15.   {
  16.     judul: "UUD 46",
  17.     no_uud: "89",
  18.     butir_1: "a. Hello World 1"
  19.   },
  20.   {
  21.     butir_1: "a. Hello World 2"
  22.   },
  23.   {
  24.     butir_1: "a. Hello World 3"
  25.   }
  26. ]
  27.  
  28. let b = []
  29. a.map((obj, index) => {
  30.   if (obj['judul']) {
  31.     b.push({
  32.       judul: obj.judul,
  33.       no_uud: obj.no_uud,
  34.       butir_1: [obj.butir_1]
  35.     })
  36.   } else {
  37.     if (b.length > 0) {
  38.       b[b.length - 1].butir_1.push(obj.butir_1)
  39.     }
  40.   }
  41. })
  42.  
  43. console.log(b)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement