Error: Cannot read property 'Title' of undefined

Error: Cannot read property 'Title' of undefined
0.0 0

#1

Tell us what’s happening:

Your code so far


function titleCase(str) {
  
 var myArr = str.split(" ");
 var kvArray = [{"Title": "value"}, 
               {"Title": "value"}, 
               {"Title": "value"}];
var rating = [];
 kvArray.map(function(elem) { 
   rating.push({title: kvArray[elem]["Title"]})  })
console.log(rating);
 
    
  return l[i];
}

titleCase("I'm a little tea pot");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence


#2

I think you need to review how a few things in JS work, your code doesn’t really make any sense at all. kvArray in particular: there’s no reason for it. And I don’t think you understand what map does - the line return l[i]; in particular bears no relation to anything that exists in your program.

Can you try to explain what you’re trying to do with your code here, what you think it is doing?