JavaScript How to add a value to an Object in javascript? object value javascript mdn,get value object javascript,key value

Let's take an example in javascript

var b = function(){
        var key = {};
        var result = [];

        var a = 
        [{people: "people1"},
        {people: "people2"},
        {people: "people2"},
        {people: "people3"}]

        for(i=0;i<a.length;i++)
         {
            var val = a[i][people];
            if(angular.isUndefined(key[val]))
            {
               Key[val] = "abc"; /////This line is foreign to my knowledge.

               result.push(val);
            }
         }
        return result;
    }

Now in this Example i am creating an object Key and a array result.

The for loop will loop through the a variable and store the value of people property in the var val.

The angular.Isundefined function check whether the key[val] contains any duplicate data if not then it will add using the

Key[val] = "abc".

1) Now i have no idea how this line is creating the value and key pair in the key object.

2) Please tell me other ways to add value to the object.

O/P is as follows

  key = Object {people1: abc, people2: abc, people3: abc}

hence it is adding value to key object without duplicating the value.

P.S. it is just an example not the real code.

Answer:1

From the link of Andreas in comments

I think this solves my problem.

the other way to add the key and value to the JSON object is like this.

obj = {};
obj[people1] = "data";
obj[people2] = "data";
obj[people3] = "data";
console.log(obj);

The key cannot be same but the value can be same.

So this is what my question was

Key[val] = "abc";

this line is getting the val variable dynamically and adding the val variable as the key and the value is abc.

Twist:

Do you think that

key.val = "abc";

work?

No: This is what provided by the site

Any property name that is not a valid JavaScript identifier (for example, a property name that has a space or a hyphen, or that starts with a number)

can only be accessed using the square bracket notation. This notation is also very useful when property names are to be dynamically determined (when the property name is not determined until runtime).

Answer:2

I'm having some issues accessing data from a tsv file. the data is on the 3rd row of the tsv. I want to access the name and print in on screen. box1.bar1 box1.bar2 box1.bar3 box1.bar4 box1....

I'm having some issues accessing data from a tsv file. the data is on the 3rd row of the tsv. I want to access the name and print in on screen. box1.bar1 box1.bar2 box1.bar3 box1.bar4 box1....

  1. access data from s3 bucket
  2. access data from pandas dataframe
  3. access data from table matlab
  4. access data from observable angular
  5. access data from docker container
  6. access data from method vue
  7. access data from another sheet in excel
  8. access data from broken phone
  9. access data from old hard drive
  10. access data from dictionary python
  11. access data from phone with broken screen
  12. access data from pointer c++
  13. access data from struct matlab
  14. access data from datatable c#
  15. access data from object javascript
  16. access data from json object
  17. access data from api
  18. access data from json file
  19. access data from app.config c#
  20. access data from child component vue

i'm trying to use angular directives with prototype or object initializer. Examples: Prototype: 'use strict'; var Example = function Example($scope, $elem) { this.$scope = $scope; this.$elem = $...

i'm trying to use angular directives with prototype or object initializer. Examples: Prototype: 'use strict'; var Example = function Example($scope, $elem) { this.$scope = $scope; this.$elem = $...

  1. using angular directives
  2. @ in angular directive
  3. u003d in angular directive scope
  4. angular use directive from another module
  5. use directive angular 6
  6. angular use directive on component
  7. use directive angular 7

i'm trying to fetch data from oracle database and store it into an array using JavaScript . but the output I'm getting "undefined". how can i fix it?Can anyone help me. <!DOCTYPE HTML PUBLIC "-//...

i'm trying to fetch data from oracle database and store it into an array using JavaScript . but the output I'm getting "undefined". how can i fix it?Can anyone help me. <!DOCTYPE HTML PUBLIC "-//...

  1. fetching data from api
  2. fetching data from api react
  3. fetching data from an api using react/redux
  4. fetching data from firebase
  5. fetching data from database in java
  6. fetching data from multiple tables in jpa
  7. fetching data from nested table in oracle
  8. fetching data from cdhdr and cdpos table
  9. fetching data from database
  10. fetching data from database in php
  11. fetching data from database in django
  12. fetching data from firebase android
  13. fetching data from api in angular
  14. fetching data from json file
  15. fetching data from two tables in sql
  16. fetching data from api in react native
  17. fetching data from api in flutter
  18. fetching data from database in laravel
  19. fetching data from multiple tables in sql
  20. fetching data from mongodb

I have an SVG path which is just like an outline of a cup, and I was wondering how I can animate a fill to fill it up with water like blue liquid that slowly rises up in the cup? All the tutorials ...

I have an SVG path which is just like an outline of a cup, and I was wondering how I can animate a fill to fill it up with water like blue liquid that slowly rises up in the cup? All the tutorials ...

  1. animate weapon
  2. animate dead 5e
  3. animate guardian
  4. animate object 5e
  5. animate definition
  6. animate css
  7. animate weapon 3.10
  8. animate guardian poe
  9. animate cc
  10. animate a name
  11. animate objects
  12. animate online
  13. animate weapon build
  14. animate dead mtg
  15. animate me
  16. animate yourself
  17. animate dead pathfinder
  18. animate online shop
  19. animate synonym
  20. animate a picture