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

266
Views
How to delete the last two characters of a number if it contains a slash (vue.js)

I have a little problem with my code:

<template slot="popover">
  <img :src="'img/articles/' + item.id + '_1.jpg'">
</template>

Some of my item.id numbers (Exsample: 002917/1) have a slash in them. As a result, some images are not displayed. Now I would like to delet the last two charakters when there is an slash in the number. Is there a simple solution for this?

The slash should only be deleted at this point in the code and not in another place where the item.id is used.

I am very new to vue and javascript so please have mercy.

I am using the vue version 16.13.1

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

0

You could also use split. This will always give the correct result, even if there is no slash contained in the id.

<template slot="popover">
  <img :src="'img/articles/' + item.id.split('/')[0] + '_1.jpg'">
</template>
about 4 years ago · Juan Pablo Isaza Report

0

You can simply use slice here as:

const num = "002917/1";
const result = num.includes("/") 
                ? num.slice(0, -2) 
                : num;
console.log(result);

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!