删除列表中的最后一项 [英] Delete Last Item in A List

查看:78
本文介绍了删除列表中的最后一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于你们所有人来说非常简单的问题。我是总菜鸟

和js。我有一个名为drawPathList的列表,它只是一个xy

坐标列表。我用它在地图上构建一幅画。然而,

人们希望能够撤消他们绘制的东西,

所以我想要抓住给定的最后一项清单。


drawPathList如下所示:23,34 || 45,67 || 456,678 || 43,48


有人可以提供帮助我有一个功能来删除

列表中的最后一项(无论长度如何)?谢谢大家。

解决方案

文章< 11 ***************** ***@k79g2000hse.googlegroups.c om>, bu ******** @ gmail.com 写道:


>非常简单的问题给你们所有人。我是job的总菜鸟。我有一个名为drawPathList的列表,它只是一个xy
坐标列表。我用它在地图上构建一幅画。然而,
人们希望能够撤消他们绘制的东西,
所以我想在给定列表中抽出最后一项。

drawPathList看起来像这样:23,34 || 45,67 || 456,678 || 43,48

有人可以帮我一个删除
列表中最后一项的功能(不管长度)?谢谢大家。



在我看来,将它作为一个字符串数组实现更有意义,

而不是单个字符串你似乎现在拥有它。然后从n个项目的数组中删除

nth元素是微不足道的。


-

问候,

Doug Miller(在milmac dot com上的alphageek)


现在是时候把他们所有的该死的茶再次扔到港口了。


琐碎是这里的关键词。现在,我想我已经坚持使用

单字符串,但我会考虑改变它的创建方式。如果你对
有任何关于如何使用字符串的见解,我很乐意听到它。


11月9日,1:07 pm,spamb ... @milmac.com(Doug Miller)写道:


文章< 1194630233.307238.6 ... @ k79g2000hse.googlegroups.c om> ,buddhat ... @ gmail.com写道:


非常简单的问题,你们所有人都在那里。我是总菜鸟

和js。我有一个名为drawPathList的列表,它只是一个xy

坐标列表。我用它在地图上构建一幅画。然而,

人们希望能够撤消他们绘制的东西,

所以我想要抓住给定的最后一项名单。


drawPathList如下所示:23,34 || 45,67 || 456,678 || 43,48

< blockquote class =post_quotes>
有人可以通过函数帮我删除

列表中的最后一项(无论长度如何)?谢谢大家。



对我来说,将它作为一个字符串数组实现更有意义,

而不是单个字符串,因为你看起来像现在拥有它。然后从n个项目的数组中删除

nth元素是微不足道的。


-

问候,

Doug Miller(在milmac dot com上的alphageek)


现在是时候把他们所有的该死的茶再次扔进港口了。



buddhat ... @ gmail.com写道:


drawPathList看起来像这样:23,34 || 45,67 || 456,678 || 43,48


有人可以帮我一个功能去除
$中的最后一项b $ b列表(无论长度如何)?



通常的代码:


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 noob
with js. I have a list called drawPathList thats just a list of xy
coordinates. 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,78

Can someone help me with a function to remove the last item in the
list (regardless of length)? Thanks all.

解决方案

In article <11********************@k79g2000hse.googlegroups.c om>, bu********@gmail.com wrote:

>Very simple question for all you folks out there. I am total noob
with js. I have a list called drawPathList thats just a list of xy
coordinates. 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,78

Can someone help me with a function to remove the last item in the
list (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 the
nth 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.


Trivial is the key word here. For now, I think I''m stuck with the
single string, but I''ll look at changing how it gets created. If you
have any insight on how to do it with the string, I''d love to hear it.

On Nov 9, 1:07 pm, spamb...@milmac.com (Doug Miller) wrote:

In article <1194630233.307238.6...@k79g2000hse.googlegroups.c om>, buddhat...@gmail.com wrote:

Very simple question for all you folks out there. I am total noob
with js. I have a list called drawPathList thats just a list of xy
coordinates. 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,78

Can someone help me with a function to remove the last item in the
list (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 the
nth 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.



buddhat...@gmail.com wrote:

drawPathList looks like this: 23,34||45,67||456,678||43,78

Can someone help me with a function to remove the last item in
the list (regardless of length)?

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)+


这篇关于删除列表中的最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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