1

Given a table, when the user selects a row I save the values of that row in an array.

Code:

var outer_array = []
//loop through checked checkboxes
$("tbody input[type=checkbox]:checked").each(function(index, item) {
    var inner_array = []
    var selector = $(this).closest("tr") //get closest tr
    //loop through trs td not first one
    selector.find("td:not(:first)").each(function() {
        inner_array.push($.isNumeric($(this).text().trim()) ? Number($(this).text().trim()) : $(this).text().trim())
        //push in inner array
    })
    outer_array.push(inner_array) //push in outer array
})

For some reason, inner_array contains unwanted characters such as the byte: "b'\x00'"

These characters cause me problems on the back-end as python interprets backslash as a special character.

How could I get rid of those unwanted byte characters?

For example, instead of pushing that byte, I would like to push an empty string (pseudo):

if (byte_code){
    innter_array.push('')
} else {
    inner_array.push($.isNumeric($(this).text().trim()) ? Number($(this).text().trim()) : $(this).text().trim());
}

enter image description here

1 Answer 1

2

Just replace them before

It is also more DRY

const text = $(this).text().trim().replace(/b'\\x00'/g,"")
inner_array.push($.isNumeric(text) ? Number(text) : text)
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.