Tell us what’s happening:
How may I do access to the values without using strings? I could accomplished whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }) should return [{ first: "Tybalt", last: "Capulet" }] but, I do not hot to stop using strings to access.
Your code so far
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
let a=Object.values(collection)
let b= Object.keys(source)
console.log(a[1])
console.log(b)
for(let i=0;i<=collection.length;i++){
if(a==b |a[i]==b){
arr.push(collection[2])
}
}
console.log(arr)
// Only change code above this line
return arr;
}
whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Arrays and Objects are 0 indexed, which means the “count” of each item starts at 0.
So if I have the array [a, b, c]… the array.length would be 3, but the positions would be [0, 1, 2]. You cannot used <= to compare length because array[3] doesn’t exist.
I could complete the first two challenges, but when I tried to use conditions. It couldn`t get the third one, so what may I do to get the challenge done? What can I read?
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
//console.log(collection)
//console.log(...collection)
//console.log(source)
//console.log(Object.keys(collection))
//console.log(Object.keys(...collection))
//console.log(Object.values(collection))
//console.log(Object.values(collection)[2])
console.log(Object.values(collection)[2][Object.keys(source)])
//console.log(Object.values(collection)[0][Object.keys(source)])
//console.log(Object.values(...collection))
//console.log(Object.keys(source))
//console.log(Object.values(collection))
//console.log(Object.values(source))
console.log(Object.values(source)[0])
for(let i=0;i<collection.length;i++){
if(Object.values(source)[0]==Object.values(collection)[i][Object.keys(source)]){
arr.push(Object.values(collection)[i])
}
}
// Only change code above this line
console.log(arr)
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });