我得到返回并且是一个字符串的聚合列表。我只想显示两个项目并删除其余项目。寻找在JavaScript中做到这一点。返回带有匹配关键字的前两个字符串
我有一些看起来像这样:
"type:of:pets:pet:304126008:pet:328464062:pet:329003654:pet:274825265:pet:302508993"
我想返回前两个宠物和剥除休息:
"type:of:pets:pet:304126008:pet:328464062"
我试着这样做:
var types = "type:of:pets:pet:304126008:pet:328464062:pet:329003654:pet:274825265:pet:302508993"
types.split('type:of:pets:pet', 2);
看起来它并不考虑我需要的数字。
那你试试?你有任何代码要显示吗? http://stackoverflow.com/help/how-to-ask – YoannM