In javascript, is there anyway to set a value equal to a previous key that was declared during initialization? for example,
const object = {
a: "test",
b: a
}
console.log(object)
or
const object = {
a: "test",
b: object.a
}
console.log(object)
How can I achieve this result in the console?
{ a: 'test', b: 'test' }
I understand that this is redundant, so let me explain what I'm trying to achieve.
I want to be able to set a url in one value, and then add to it using a previous value. The reason for this is to clean up the code and set formulas into one object.
Example
const object = {
base_url: "www.google.com",
images_url: `${base_url}/images`,
maps_url: `${base_url}/maps`
}
console.log(object)