Jacob
Jacob

Reputation: 4031

Create object with reserved words (JavaScript)

How can I create an object like this in JS since public and private are reserved words

keyObject = {
    public : {
        iv: "123",
        key: "123"
    },   
    private : {
        key: "123"
   }
}

Upvotes: 0

Views: 66

Answers (2)

pawel
pawel

Reputation: 36965

Quote the keys, like this:

var keyObject = {
    "public" : {
        iv: "123",
        key: "123"
    },
    "private" : {
        key: "123"
    }
}

http://jsfiddle.net/5tUXy/

Upvotes: 1

John Smith
John Smith

Reputation: 625

you can define keys as strings

keyObject {
    'public': {
        iv: "123",
        key: "123"
    },
    'private': {
        key: "123"
    }
}

Upvotes: 0

Related Questions