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

240
Views
Cannot read properties of undefined (reading 'slice')

I can't figure out the problem with the code as I have even matched it with the source code provided by the git user and it is same, but still showing error So below is the error:- error

Below is the code for shortenAddress component:-

 export const shortenAddress = (address) => `${address.slice(0, 5)}...${address.slice(address.length - 4)}`;

Below is the code of the Welcome component

        <p className="text-white font-light te-xt-sm">{shortenAddress(currentAccount) }</p>

Please,can someone tell the answer to this question of mine...

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

0

The issue is because, when you wont get address then address is undefined and not an array.

What you can do is, check address exists like

export const shortenAddress = (address) => {
  if(address.length) {
    return `${address.slice(0, 5)}...${address.slice(address.length - 4)}`
  }
  return address
}

OR you can also optional chaining ? operator:

export const shortenAddress = (address) => `${address?.slice(0, 5)}...${address?.slice(address.length - 4)}`;

Let me know, if you feel any issue.

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!