0

Im a newbie to this coding thing and cant get over this hump in my practice problem. is says in my parameter when I have over it "is declared but value never read". I tried making it equal to something else but nothing. this is the function:

function pluck(arr,value) {
var obj = arr;
let val = [];
let name = value;
for (let i=0;i<obj.length;i++){
    val.push(`${obj[i].name}`);
}

return val; 

//this is part of my tss practice problems, i just need some more guidance on this. "value" is the thing im having problems with.

I tried renaming the "value" in the argument to "name" so i could use it in my obj[i].name function since im dealing with an array with objects nested inside. but "name" became the new thing not used.

jason.p
  • 1
  • 1
  • You are using the parameter `value` to initialise `name`, but you are not using the `name` variable. – Bergi Jul 15 '23 at 22:32
  • I'd guess what you actually want is [`val.push(arr[i][name])`](https://stackoverflow.com/q/4244896/1048572) – Bergi Jul 15 '23 at 22:33
  • thanks for replying Bergi, to give you some more information, this function is for an object, nested in an array. – jason.p Jul 16 '23 at 17:16
  • Yes, I already inferred that from [the name `pluck`](https://stackoverflow.com/search?q=pluck+%5Bjs%5D). Does my suggestion work for you? – Bergi Jul 16 '23 at 17:23
  • YES! I didn't know that it would run the same as "obj[i].value". I ended up doing away with "let name=value" entirely. Thanks so much! I'll try to implement this in other functions I'm stuck on with similar problems. – jason.p Jul 16 '23 at 18:41

0 Answers0