Profile Look Up: Not able to understand why it does not work in

Confused in Profile Look up chapter in Js course
Code that works:

function lookUpProfile(name, prop) {
   for(let i = 0; i < contacts.length; i++){
    if(contacts[i].firstName === name){
        return contacts[i][prop]; ==**=> IF I CHANGE [prop] WITH  .prop I GET AN ERROR**
        return "No such property";
  return "No such contact";

What I have done in changed

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi @SujanPasa !

Welcome to the forum!

This article does a good job of explaining when to use dot versus bracket notation.
It will help you understand why you can’t use dot notation here.

Hope that helps!

Thank you I will take care of it from next time

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.