K
K
kickass772021-04-21 01:37:55
css
kickass77, 2021-04-21 01:37:55

How to make array output js split?

Hello.
Please fix how to do it right...

if( typeof respond.error === 'undefined' ){

        var files_path = respond.files;
        
        console.log("HELLO 2");
        
        var html = '';
        $.each( files_path, function( key, val ){ html += val +'<br>'; } )
  
        var str = html;
        var re = str.split("/home/user/www/");
        html = "https://" + re[1];
            
        $('.ajax-respond').html( html );
      }


The point is that I can have several elements, but I need to remove the excess and for this I use split.
If there is only one element, everything is fine.
If there are several elements, it displays only 1 element.

How can I make it work the same way it worked without split?
I understand that you need to set an array, but I can’t catch up with something.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Proskurin, 2018-08-02
@Vlad_IT

I think it's a generic background with two radial gradients. And in front of 3 gradients make translucent.

P
Pantene742, 2018-08-02
@Pantene742

a few svgs as an option. You have to try several ways.

M
MikUrrey, 2021-04-21
@kickass77

//...начиная со строки с $.each:

$.each( files_path, function( key, val ){ 
  html += "https://" + val.replace(/^\/home\/user\/www\//, "") +'<br>'; 
} )
//... остальное убираем и далее:
$('.ajax-respond').html( html );

that is, in order for the processing to go through all the elements, we put all the transformations in a loop.
As for the regular expression: if "/home/user/www/" is always expected only at the beginning, then it is valid. If this substring can be in the middle of the string, then replace it with this:
/.*\/home\/user\/www\//

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question