0

I got item a, which is an javascript object I think?

const item = myItem.getAsFile();

which returns something like

lastModified: 1521979332955
name: "image.png"
size: 15254
type: "image/png"
webkitRelativePath: ""

Next I create a object url:

const preview = window.URL.createObjectURL(item);

which returns "blob:https://localhost:3000/..."

Now I want to "push" preview: "blob:https://localhost:3000/..." inside my const item, so that next to lastModified, name, size, etc. preview: will be listed.

How can I do this?

7
  • 4
    item.preview = preview will work. Commented Mar 25, 2018 at 12:09
  • Change const to var or let so you can change item. Then use item.preview = preview to add the attribute to the object. Commented Mar 25, 2018 at 12:11
  • 1
    Where are the arrays advertised in the question title?! Commented Mar 25, 2018 at 12:11
  • 6
    @Tostifrosti const does not prevent the modification of item. It just disables storing another value in item. Commented Mar 25, 2018 at 12:13
  • It is really simple thing, seems it must not be a question. developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/… Commented Mar 25, 2018 at 12:13

1 Answer 1

2

You can do the following:

item.preview = preview;

if you don't want to change the origin item, you can use Object.assign

let newItem = Object.assign({}, item, {preview: preview})
Sign up to request clarification or add additional context in comments.

Comments

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.