-2

Let's say i declaring an object

let Mahasiswa = {
    name: "Steve",
    age: 22
}

And then later in my code i copy these code with same name;

let {name, age} = Mahasiswa;
console.log(name, age) // Steve 22

but how do i change it to different variable name?

let {name as Player, age as ID} = Mahasiswa;
console.log(Player, ID) // Steve 22
trp
  • 9
  • 1
  • 1
  • 4
  • 1
    No, this is JS--the `as` is just pseudocode to indicate what OP is trying to achieve with a rename. – ggorlen Aug 01 '20 at 17:08

1 Answers1

2

We use :

let Mahasiswa = {
  name: "Steve",
  age: 22
}

let {
  name: Player,
  age: ID
} = Mahasiswa;

console.log({ Player, ID });
Adam Azad
  • 11,171
  • 5
  • 29
  • 70