How to i can remove string from text file ?
fs.readFile('./banlist.txt', function read(err, data) {
if (err) {
throw err;
}
lastIndex = function(){
for (var i = data_array.length - 1; i > -1; i--)
if (data_array[i].match(ip))
return i;
}()
delete data_array[lastIndex];
});
But console give me message: data_array is not defined. I want to remove ip adress line.
data_array? I don't see it in this code snippet.fs.readFiledoes not populate data as an array, secondly strings are immutables. The delete key word only works on the members of an object.data_arrayis not defined any where. Check the arguments in your function if they are correctvar newData = data.toString().split('\n').filter(val=>val!==ip).join('\n')and then write newData (string) back to the file.