What does this square bracket suffix at the end of the object definition in JavaScript mean?

Related searches

JavaScript code

I was browsing someone's code on GitHub and came across this and have no idea what this means. I would have googled but I am new to JavaScript and have no idea how to google it. Any information would be appreciated!

var charStr = String.fromCharCode(evt.which);
var value   = (evt.type == 'keydown') ? true : false;

idx = {
  '1': 0x1,'2': 0x2,'3': 0x3,'4': 0x4,
  'Q': 0x4,'W':0x5,'E': 0x6,'R': 0xD,
  'A': 0x7,'S':0x8,'D': 0x9,'F': 0xE,
  'Z': 0xA,'X':0x0,'C': 0xB, 'V':0xF,
}[charStr];

This is the same as saying:

const idxObj = {
  '1': 0x1,'2': 0x2,'3': 0x3,'4': 0x4,
  'Q': 0x4,'W':0x5,'E': 0x6,'R': 0xD,
  'A': 0x7,'S':0x8,'D': 0x9,'F': 0xE,
  'Z': 0xA,'X':0x0,'C': 0xB, 'V':0xF,
};
idx = idxObj[charStr];

It is creating the object and accessing an object property at the same time.

Further reading: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation

JavaScript Objects, Square Brackets and Algorithms, Our car object will have three properties: make , model and color . Another way to refer to a property is using square bracket notation: That means if the number of books in our collection doubles, the cost of finding a book� 1 What does this square bracket suffix at the end of the object definition in JavaScript mean? Feb 18 '19 0 Implementing custom ECDH into OpenSSL 1.1.0e using Windows CNG API Dec 5 '19

basically what you are seeing is the accessing of a property in an object directly in the same definition.

lets use a simplier example:

const ourObjectResponse = {
    foo: 'bar'
}['foo']
console.log(ourObjectResponse) // 'bar'

this is because what you are doing is defining an object and inmediatly getting a value from that object.

you can change this to be something like:

const ourObject = {
    foo: 'bar'
};
const ourObjectResponse = ourObject['foo']
console.log(ourObjectResponse) // 'bar'

Back to Basics: JavaScript Object Syntax, In bracket notation, the object name is followed by a set of square brackets. Inside the square brackets, the property name is specified as a string. It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered.

You can access property of object using square box notations. This is helpful usually in cases where the property has space in it. Like obj[‘first name’].

JavaScript Arrays, Creating arrays in JavaScript is easy with the array literal notation. elements can be arbitrary expressions; var suffix = "tree";; var trees = ["Oak" + suffix, name, similar to the square bracket notation of objects to access their properties. that JavaScript arrays are dynamically sized, meaning that you will never see array� 3 What does this square bracket suffix at the end of the object definition in JavaScript mean? Feb 18 '19. 2 2D Array only showing last element in Text function Jul

Grammar and types, For example, the word Fr�h (which means "early" in German) could be But, the variable fr�h is not the same as Fr�h because JavaScript is also has rules for automatic insertion of semicolons (ASI) to end of which represents an array element, enclosed in square brackets ( [] ). Character, Meaning� These are used to indicate that a direct quote has been edited — to fit the surrounding information, or to add context that does not show up within the scope of the quote. This page has a more detailed description: Square brackets are used around words that are added that are not part of the original quote.

Regular Expressions :: Eloquent JavaScript, But the period itself, between square brackets, loses its special meaning. The i at the end of the expression in the example makes this regular expression Other than that, the object looks like (and in fact is) an array of strings, whose first 10 to 15) followed by an h, or a regular decimal number with no suffix character . What does this square bracket suffix at the end of the object definition in JavaScript mean? February 2019 Constructing a new Pandas Dataframe using combined string and list as column headers

Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec() and test() methods of RegExp, and with the match(), matchAll(), replace(), replaceAll(), search(), and split() methods of String. This chapter describes JavaScript regular expressions.

Comments