本文介绍了删除列表中的最后一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 对于你们所有人来说非常简单的问题。我是总菜鸟 和js。我有一个名为drawPathList的列表,它只是一个xy 坐标列表。我用它在地图上构建一幅画。然而, 人们希望能够撤消他们绘制的东西, 所以我想要抓住给定的最后一项清单。 drawPathList如下所示:23,34 || 45,67 || 456,678 || 43,48 有人可以提供帮助我有一个功能来删除 列表中的最后一项(无论长度如何)?谢谢大家。 解决方案 在我看来,将它作为一个字符串数组实现更有意义, 而不是单个字符串你似乎现在拥有它。然后从n个项目的数组中删除 nth元素是微不足道的。 - 问候, Doug Miller(在milmac dot com上的alphageek) 现在是时候把他们所有的该死的茶再次扔到港口了。 有人可以通过函数帮我删除 列表中的最后一项(无论长度如何)?谢谢大家。 对我来说,将它作为一个字符串数组实现更有意义, 而不是单个字符串,因为你看起来像现在拥有它。然后从n个项目的数组中删除 nth元素是微不足道的。 - 问候, Doug Miller(在milmac dot com上的alphageek) 现在是时候把他们所有的该死的茶再次扔进港口了。 通常的代码: var drawPathList = [''23,34'','''','45',67' ','''456,678'',''43,78''; drawPathList.pop(); alert(drawPathList); 使用正则表达式的一维文字解决方案: var drawPathList ='''23,34 || 45,67 || 456,678 || 43,48 | |''; drawPathList = drawPathList.replace(/ \ | \ |(,| \d)+ Very simple question for all you folks out there. I am total noobwith js. I have a list called drawPathList thats just a list of xycoordinates. I use this to construct a drawing on a map. However,people would like to be able to ''Undo'' something that they have drawn,so I''d like to yank that last item in a given list.drawPathList looks like this: 23,34||45,67||456,678||43,78Can someone help me with a function to remove the last item in thelist (regardless of length)? Thanks all. 解决方案Seems to me it would make more sense to implement that as an array of strings,rather than a single string as you appear to have it now. Then deleting thenth element from an array of n items is trivial.--Regards,Doug Miller (alphageek at milmac dot com)It''s time to throw all their damned tea in the harbor again.Seems to me it would make more sense to implement that as an array of strings,rather than a single string as you appear to have it now. Then deleting thenth element from an array of n items is trivial.--Regards, Doug Miller (alphageek at milmac dot com)It''s time to throw all their damned tea in the harbor again.The usual code:var drawPathList = [''23,34'', ''45,67'', ''456,678'', ''43,78''];drawPathList.pop();alert(drawPathList);One-dimensional literal solution using a regular expression:var drawPathList = ''23,34||45,67||456,678||43,78||'';drawPathList = drawPathList.replace(/\|\|(,|\d)+ 这篇关于删除列表中的最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-11 03:49