How node.js reads numbers at a specific location

RT. I keep a lot of numbers in a file, all separated by newline (n).
for example:
1
2
3
4
saved like this, how can you take out the value of a specific location, for example, if you want to take out the value of 3, or always take out the penultimate value?

Mar.10,2021

text.txt content:

1
2
3
4
5
6

the code is as follows:

const fs = require('fs')
const fileName = './test.txt'

let content = fs.readFileSync(fileName, 'utf-8')
/*  */
let arr = content.split(/[\s]*\n[\s]*/)
console.log(arr) // [ '1', '2', '3', '4', '5', '6']
After

is cut into array , the value can be taken by specifying the location.

Menu