Domanda

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"
   }
}
È stato utile?

Soluzione

Quote the keys, like this:

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

http://jsfiddle.net/5tUXy/

Altri suggerimenti

you can define keys as strings

keyObject {
    'public': {
        iv: "123",
        key: "123"
    },
    'private': {
        key: "123"
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top