0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【JavaScript】基礎の基礎 - 零ゼロ - ほぼ自分へのメモ

Last updated at Posted at 2025-07-19

外部入力からのデータ取得

// processモジュールのstdin・メソッドを呼び出している
// stdinというのがstandard(標準)input(入力)の略
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_string = "";

// readlineのモジュールを読み込み
var render = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// 外部入力データの取得
render.on('line', (line) => {
    input_string = line;
});

// 入力データの出力
render.on('close', () => {
    console.log("Hello " + input_string );
});

複数行のデータ入力を表示する

配列の各インデックスに格納される

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_string = [];

var render = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// 外部入力データの取得
render.on('line', (line) => {
    lines.push(line);
});

// 入力データの出力
render.on('close', () => {
    for (let i=0; i<3; i++) {
        console.log( lines[i] );
    }
});

型のパース(parse)

// 数値へ変換
parseInt()

// 文字へ変換
String(num); 

Jsonファイルのパース

JSONのデータはそのままでは表示できないので、JSON.parse()でデコード

var obj = {
    name: 'Sato',
    age: 28,
    area: 'Osaka'
}

var json = JSON.stringify(obj);

var ParsedJson = JSON.parse(json);
console.log(ParsedJson);
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?