2

Eslint yells at me about this line because it should be done with array destructuring :

postModel.base64File = formFile.split(',')[1];

I am concerned because I cannot find a way to do this in a single instruction. The best I came up with is the following :

const [, b64] = formFile.split(',');
postModel.base64File = b64;

Is there a way to make this assignment in a single instruction ?

1 Answer 1

2

You could destructure to the property directly.

var postModel = {},
    formFile = 'a,b';

[, postModel.base64File] = formFile.split(',');

console.log(postModel);

The same with an object and an index as target.

var postModel = {},
    formFile = 'a,b';

({ [1]: postModel.base64File } = formFile.split(','));

console.log(postModel);

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, thanks ! I was close with const [, postModel.base64File] = formFile.split(',');, which generated about 1 million more errors !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.