对包含数字的 JavaScript 字符串数组进行排序 [英] Sort JavaScript String Array containing numbers

查看:26
本文介绍了对包含数字的 JavaScript 字符串数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JavaScript 中有一个数组,其中包含以下内容:

I have an array in JavaScript that contains the following:

  • [值 1",值 5"."值 10", "值 11"];

我将如何对该数组进行排序以使其不会如下所示:

How would I go about sorting this array so that it does not appear as follows:

  • [值 1",值 10"."值 11", "值 5"];

但是作为:

  • [值 1",值 5"."值 10", "值 11"];

任何帮助都会很棒.

推荐答案

如果你热衷于自己编写,你可以用正则表达式解析项目并比较第二部分.那些将匹配类似

If you are enthusiastic about writing it yourself, you can just parse the items with an regular expression and compare the second part. Those will match something like

"值\s[1-9][0-9]*"

"Value\s[1-9][0-9]*"

这篇关于对包含数字的 JavaScript 字符串数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆