Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
How to pass data from object into new array in javascript?

I want to send only one of the fields contained in the data object var arrImg. The first thing I want to push is an image field of var arrImg with a condition where checked is true into the new array image on crudData:{'image':[]}. Then the second I want to push the field name of var arrImg with a condition where checked is true into a new array name on crudData:{'name':[]}. Checked value is set to false first, but will change to true when the input checkbox is clicked. Does someone understand for the case I'm asking? i'm new to javascript. Thanks.

Here's myfiddle https://jsfiddle.net/Annisa_Lianda30/d0ber5Lu/24/

This is my code:

<script>
export default {
    data() {
        return{
            crudData:{
                'id': null,
                'name': [],
                'image': [],
                'arrImage': [],
            },
        }
    },

    imageUpload(e, maxItem){                    
            let input = this.$refs.uploadImage
            let file = input.files
            if(file.length > (maxItem - this.crudData.arrImage.length)){
                $('#uploadMultiFile').val('')
                alert('You can only upload max '+maxItem+' items')
            } else {
                for(let i = 0; i < file.length; i++){
                    var valueArr = this.crudData.arrImage.map(function(item){ return item.fileName })
                    var isDuplicate = valueArr.some(function(item, idx){ 
                        return item == file[i].name 
                    })
                    if (isDuplicate) {
                        alert("You've already uploaded this file")
                        continue
                    }else{
                        var arrImg = {
                            blob: URL.createObjectURL(file[i]),
                            image: file[i],
                            fileName: file[i].name,
                            checked: false,
                            name : null
                        }
                        this.crudData.arrImage.push(arrImg)
                        console.log(this.crudData.arrImage)
                    }
                }
            }
        },
        uploadImage(e){
            this.$refs.uploadImage.click()
        },
        removeImage(key){
            this.crudData.arrImage.splice(key, 1)
        }, 

}

This is the output i got from crudData.arrImage: Output Javascript

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Welcome to SO. Hopefully this code snippet can help guide you towards what your looking for.

let checkedImages = this.crudData.arrImage.filter(img => img.checked)
let imageFiles = checkedImages.map(img => img.image)
let names = checkedImages.map(img => img.fileName)
console.log({ imageFiles,names })
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!