0
var a = {
    properties:{
        title:{
            type:"String",
            value:"sss"
        },
        content:{
            type:"String",
            value:"555"
        }
    },
    data:{
        abc:123,
        ddd:444,
        fff:"dd"
    },
    methods: {
        abc () {

        },
        cde () {

        }
    }
}

The code above is a text string from js file(got by fs.readFileSync). I need to get the part of 'properties' string by regex and parse it to a json object.

cson
  • 37
  • 6
  • 1
    `a.properties` is enough i guess, – Code Maniac May 27 '19 at 05:26
  • Possible duplicate of [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – Adan Rehtla May 27 '19 at 05:36
  • no..I read it from a js file(got by fs.readFileSync). So the code above is text string. I need to get the part of 'properties' string by regex and parse it to a json object. – cson May 29 '19 at 04:38

1 Answers1

1

You can use object Destructuring

const {properties} = a;

var a = {
  properties: {
    title: {
      type: "String",
      value: "sss"
    },
    content: {
      type: "String",
      value: "555"
    }
  },
  data: {
    abc: 123,
    ddd: 444,
    fff: "dd"
  },
  methods: {
    abc() {

    },
    cde() {

    }
  }
}

const {properties} = a;

console.log(properties);

or access using dot operator

a.properties

or

a["properties"]

random
  • 7,756
  • 3
  • 19
  • 25
  • no..I read it from a js file(got by fs.readFileSync). So the code above is text string. I need to get the part of 'properties' string by regex and parse it to a json object. – cson May 29 '19 at 04:42