0

I have array like this below

const spetialCharector = [
                          "http://www.curryconfigurator.org/cc#Quantity", 
                          "http://purl.org/heals/food/Texture",
                          "http://www.curryconfigurator.org/cc#FoodItem",
                          "http://www.w3.org/2001/XMLSchema#float"
                          "http://purl.org/heals/food/hasIngredient"
                          ]

but i want the output like this below

const RemoveSpecialCharectorArray =["Quantity" , "Texture" , "FoodItem" "float" , "hasIngredient"]

Anyone can help me out please if it solved that so much appreciatable

1
  • 1
    That’s the fragment of the URL or, if it doesn’t exist, the last part of the pathname of each URL. spetialCharector.map((url) => { const url = new URL(url); return url.hash.slice(1) || url.pathname.split("/").slice(-1)[0]; }); should get you started. Commented Mar 11, 2022 at 7:37

1 Answer 1

1

const input = [
          "http://www.curryconfigurator.org/cc#Quantity", 
          "http://purl.org/heals/food/Texture",
          "http://www.curryconfigurator.org/cc#FoodItem",
          "http://www.w3.org/2001/XMLSchema#float",
          "http://purl.org/heals/food/hasIngredient"
          ]
          
let output = input.map((item) => {
  let slashSplit = item.split('/')
  let hashtagSplit = slashSplit[slashSplit.length-1].split('#')
  return hashtagSplit[hashtagSplit.length-1]
  }
 )
  
console.log(output)

Sign up to request clarification or add additional context in comments.

1 Comment

Using the URL API would make this a lot safer. This won’t work for https://example.com/path?param=1#some/fragment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.