简体   繁体   English

未捕获的TypeError:arrayName.sort不是函数

[英]Uncaught TypeError: arrayName.sort is not a function

  • I am trying to sort the values using the map method. 我正在尝试使用map方法对值进行排序。
  • but I am getting an error Uncaught TypeError: arrayName.sort is not a function. 但是我收到一个错误Uncaught TypeError:arrayName.sort不是一个函数。
  • can you tell me how to sort it. 你能告诉我如何排序吗?
  • can you tell me how to solve using the below methods, since I am learning functional programmming 您能告诉我如何使用以下方法求解,因为我正在学习函数式编程

    .map() .filter() .find() .replace() .reduce() forEach() .map().filter().find().replace().reduce()forEach()

  • providing my code below. 在下面提供我的代码。

// ARRAY 2
const newieyork = [
  {
    name: 'Michelle',
    age: 19,
    coder:true,
    gender: 'f',
    us: true,
  },
  {
    name: 'Sam',
    age: 25,
    coder:false,
    gender: 'm',
    us: false,
  },
  {
    name: 'Ivy',
    age: 26,
    coder:true,
    gender: 'f',
    us: false,
  },
  {
    name: 'Nick',
    age: 32,
    coder:true,
    gender: 'm',
    us: true,
  },
  {
    name: 'Jim Beglin',
    age: 65,
    coder:false,
    gender: 'm',
    us: true,
  },
]

// Part 1 - List all users in US in ascending order
newieyork.sort();
//console.log("newieyork.sort();--->", newieyork.sort());
newieyork.map(function(newieyork){
  //console.log("texasss.name--->", newieyork.name);
 let arrayName =[];
arrayName = newieyork.name;
console.log("arrayName--->", arrayName.sort()); 



});

In your code you are assigning to a string: 在代码中,您正在分配一个字符串:

let arrayName =[];
arrayName = newieyork.name; // Assigning to a string

sort is not a method on a string. sort不是字符串上的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM