The task is to select unique objects from the array, and make them lower case. At the step, when I brought the array into one line and changed the register, everything is fine, but when I add a selection of unique objects, the terminal issues: TypeError: tre.reduce is not a function

var names = ['web', 'interner', 'JavaScript', 'Internet', 'script', 'programming']; var tre = names.join().toLowerCase(); var uniq = tre.reduce(function(a,b){ if (a.indexOf(b) < 0 ) a.push(b); return a; },[]); console.log(uniq); 
  • What do you mean by object? Well, reduce the array method, and you apply it to the string, because of this error - Rostyslav Kuzmovych
  • the object means a word in the array - Igor
  • you need to create an array of lowercase words, use the map function for this - Rostyslav Kuzmovych
  • something is wrong, how to register it correctly? - Igor

1 answer 1

Description of the map method

 var names = ['web', 'interner', 'InterneR', 'JavaScript', 'Internet', 'script', 'programming']; // создаем новый массив, в котором будут все те же значения, только в нижнем регистре var tre = names.map(function(e) { return e.toLowerCase(); }); var uniq = tre.reduce(function(a, b) { if (a.indexOf(b) < 0) a.push(b); return a; }, []); console.log(uniq); 

  • Thank you, it works! - Igor