What do you mean by key value pairs?


#1



You can also think of objects as combinations of key-value pairs (like arrays), only their keys don't have to be numbers like 0, 1, or 2: they can be strings and variables.


What does this sentence mean?

Replace this line with your code.


#2

Objects are like connected arrays, the elements at the same index correspond to each other.

arr1 = [1];
arr2 = ["Cade"];

//Equal To

obj1 = {
1: "Cade"
}

#3

i did not understand can you please tell me in a simple beginner language?


#4

well objects can have keys, and values:

var obj = {
  1: "test",
  2: "how",
  3: "this",
  4: "works"
};
console.log(obj[1]);

in this case, i use numbers (1 till 4) as key. They are keys of the object, then i have a bunch of strings which are values. I can now use the bracket notation to access a value with the responding key

If you don't remember this, you can always revisit the exercise where dictonary's are explained, and re-practice it


#5

i understood it thanks!


#6

keys are nothing but they are kinda like many variables(like in arrays) in objects right? and to access arrays we use 0,1,2 tc but in key it can be a string. is that correct?


#7

keys can also be strings, either way, we can use the keys to access the value associated with it.


#8

got it thanks! :slight_smile: :blush: