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

227
Views
How to append deleted from array elements by slice method?

How to delete elements from start of array and append them into end ? enter image description here

  const ImageArray = [i1,i2,i3,i4,i5]

  const clickHandler = (index: number) => {
        let start = ImageArray.slice(index)
        let end = ImageArray....
        let result = start.concat(end)
        return result
    }

    {ImageArray.map((image, index) => (
                <div
                    onClick={() => clickHandler(index)}
                    key={index} style={{backgroundImage: 'url('+image+')'}}
                />
            ))}

P.S. It's not necessary to use slice method

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

With x being the index clicked :

const arr = [0,1,2,3,4];
const newArr = [...arr.slice(1), ...arr.slice(0, 1)]
about 4 years ago · Juan Pablo Isaza Report

0

You can do:

const arr = ['i1','i2','i3','i4','i5']
const clickHandler = i => [...arr.slice(i), ...arr.slice(0, i)]

console.log('i3:', clickHandler(2)) // Clicked: 'i3'

about 4 years ago · Juan Pablo Isaza Report

0

Your function is designed to return a new array, but the place where you call the function is not doing anything with the returned value.

I assume you want to mutate ImageArray. In that case use splice to delete the first part, and push to append that same part at the end:

const clickHandler = (index: number) => {
    ImageArray.push(...ImageArray.splice(0, index));
};
about 4 years ago · Juan Pablo Isaza 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!