[]
) NotationThere are two ways to access or get the value of a property from an object — the dot (.
) notation, like obj.foo
, and the square bracket ([]
) notation, like obj[foo]
.
Where the dot notation is easier to read and write, the square bracket notation offers much more flexibility since the value between the brackets can be any variable or expression.
Therefore, if you've an object's property name stored in a JavaScript variable, you can get its value using the square bracket notation, as shown in the following example:
<script>
// Sample JS object
var obj = {
name: "Peter Parker",
age: 16,
country: "United States"
}
// Property name stored in JS variable
var prop = 'name';
// Accessing property value
alert(obj[prop]); // Outputs: Peter Parker
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to use whereIn Query in Laravel?
In this article, i will share with you v...Laravel 7 - Multiple Image Upload with Preview using AJAX
In this article, i will let you know aja...How to Send POST Request Without Waiting for Response?
In this article, I will share with you h...How To Fix GroupBy Not Working In Laravel
Recently we are working with laravel app...Laravel 5.5 - Algolia Full Text Search Example With Scout
Today, we are share with you howt o buil...