Destructuring not working , kindly help

Destructuring not working , kindly help
0

#1

Hi,

I am trying the below code but cannot extract console.log(end.column) , please guide me as to how to do it … I can do console.log(end) and it gives 2 me but then i cannot extract start.column … Thanks


var node = {
        type: "Identifier",
        name: "foo",
        loc: {
            start: {
                line: 1,
                column: 4
            },
            end: {
                line: 1,
                column: 2
            }
        },
        range: [0, 3]
    };
    
    var { loc: { start: {line, column}, end: { line, column  }  }, range } = node;


console.log(end.column)

#2

try
console.log(node.loc.end.column)


#3

Thanks it worked , buy why i needed to go up all the way to node, due to complexity of structure ?

Amit


#4

Well that is your object’s name.
Declared in the first line var node =


#5

you’ve already grabbed column from end so try console.log(column)

edit - looking this over a little further, looks like you have duplicates of line and column. Right now, only the second assignments are available so you will have to rename a set of line/column