2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

指定された配列の要素を削除する(JavaScript)

Posted at

指定された配列の要素を削除する方法です。JavaScriptで実装してみます

process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ!!
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const data = lines[0];
  const array0 = data.split(' ');
  const N = array0[0];
  const T = array0[1];
  const array1 = lines[1].split(' ');
  array1.splice(T-1,1);
  array1.forEach(data => {
      console.log(data);
  });
});

ポイントは

array1.splice(T-1,1);

でspliceメソッドを使って1番目の引数が配列の要素の順番(番目)、2番目の引数が削除する要素数になります。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?