[英]Is there a way to get corresponding index value in a 2nd array using the 1st array as a reference in Javascript?
[英]Get all indexes after 2nd index from array
我對NodeJS很陌生,我想從數組中獲取第二個索引之后的所有索引。
我的代碼如下:
module.exports.run = async(client,message,args) => {
let user = args[0];
let song = args[1];
let msg = args[2];
var data = {
user:args[0],
song:args[1],
msg:msg,
requestType: 'request'
};
我想從args數組中獲取第二個索引之后的所有索引。 我該如何實現? 謝謝。
編輯:命令將像以下命令一樣執行:
您可以使用slice
方法:
let args = [1, 2, 3, 4, 5]; let newArgs = args.slice(3); console.log(newArgs); // prints [4, 5]
您也可以使用splice
方法:
let args = [1, 2, 3, 4, 5]; let newArgs = args.splice(0,2); console.log("How many removed = ", JSON.stringify(newArgs)); console.log("What is remaining = ", JSON.stringify(args) , "length= ", args.length);
請注意:- splice
會改變您的實際陣列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.