How to use delete?

index.js

let roblox = require("./roblox.json");
let robloxc = roblox.code[Math.floor(Math.random() * roblox.code.length)];
delete robloxc

roblox.json

json { "code": [ "Unknown Roblox Account", "Unknown Roblox Account", ] }

Help in 3 line in Index.js

@SudhanPlayz,

I tried running your code in a hello-express project, and although the logs showed no errors, the code linting gave me an error saying Parsing error: deleting local variable in strict mode. But I do not have strict mode enabled…

1 Like

@khalby786
So i need to remove 'use strict'; ?

Wait…I’m working on a fix…

@khalby786
ok, i will try

@khalby786
Not worked!

@SudhanPlayz,

Does this work:

let roblox = require("./roblox.json");
// let robloxc = roblox.code[Math.floor(Math.random() * roblox.code.length)];
delete roblox.code[Math.floor(Math.random() * roblox.code.length)];
1 Like

NO I need to 2 nd line

The above kind of worked for me. When I logged roblox, this is what I got:

{ code: [ <1 empty item>, 'Unknown Roblox Account' ] }

For me nothing happened

Tell us what do you want to accomplish with this.

Also roblox.json file has two error, it should be without the word json and it has another comma at the end.

roblox.json

{ "code": [ "Unknown Roblox Account", "Unknown Roblox Account" ] }

If you only want to show a message you can use in your index.js
index.js

let roblox = require('./roblox.json');
let message = roblox.code[0];

console.log(message);

Dont do that. Save the index in avariable and then remove the element using filter or splice. Do not use a delete on arrays because the array will not be reindexed you merely delete the element leaving an undefined ati ts place. Alao dont delete local variables as its useless

1 Like

@JaielSoft
Can you give as a code

@ElBort
I just want to delete robloxc from code in roblox

@SudhanPlayz,

As @JaielSoft mentioned, you should try using splice:

let roblox = require("./roblox.json");
let index = Math.floor(Math.random() * roblox.code.length);
roblox.code.splice(index,index+1);
console.log(roblox.code);

roblox.code.splice(index,index+1);

should be

roblox.code.splice(index, 1);

because the second parameter is used to determine how many elements to delete from the index and not the end index

Yes you are right, my bad, sorry.