Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require('lodash')
- const a = [
- {
- judul: "UUD 45",
- no_uud: "123",
- butir_1: "a. Hello World"
- },
- {
- butir_1: "a. Hello World"
- },
- {
- butir_1: "a. Hello World"
- },
- {
- judul: "UUD 46",
- no_uud: "89",
- butir_1: "a. Hello World 1"
- },
- {
- butir_1: "a. Hello World 2"
- },
- {
- butir_1: "a. Hello World 3"
- }
- ]
- let b = []
- a.map((obj, index) => {
- if (obj['judul']) {
- b.push({
- judul: obj.judul,
- no_uud: obj.no_uud,
- butir_1: [obj.butir_1]
- })
- } else {
- if (b.length > 0) {
- b[b.length - 1].butir_1.push(obj.butir_1)
- }
- }
- })
- console.log(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement