0

Good day! I badly need help for this one, I have an array with many elements/data that is needed to be display in textbox. Each array element/data must be inside the textbox. (The Textbox must be dynamically set up using loop with the array data inside it)


                    
                        arr = ["1"-"2"-"3"-"4"-"5"]; //my array is from the db, this is example only
                        conv_arr = arr.split("-")
                        
                        var myArray = [conv_arr];
                        
                        var ArrayInText = document.createElement('input');

                        myArray.forEach(function(conv_arr) {

                        ArrayInText.value = conv_arr ;
                        
                        document.body.appendChild(ArrayInText);

It displays the array (pretend this is a textbox [ ]) [ 1, 2, 3, 4, 5 ]

I want a result that looks like this (One textbox per element using loop) [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]

1 Answer 1

2

You can see the demo here=> https://jsfiddle.net/4ow6k8j5/1/

After removing unnecessary assignments, you can use below simplest solution;

conv_arr = arr.split("-")

conv_arr.forEach(function(elem) {
  var ArrayInText = document.createElement('input');
  ArrayInText.value =  elem ;
  document.body.appendChild(ArrayInText);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.