In solidity ,can push command be used for adding an element to a byte data type , this guy on yt did , on the net it says its only for dynamic array?

Viewed 94
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract dynamicsizedbyte{

    bytes public by1;

    function setvalue() public {
        by1="abcdefgh";
    }
    
    function pushelement() public {
        by1.push(10);
    }
}

im getting this error

TypeError: Member "push" not found or not visible after argument-dependent lookup in bytes storage ref.

1 Answers

The best high-level approach I could come up with is overriding the whole value with a newly-created byte array. Hoping someone finds a more efficient solution, should be possible using the Solidity assembly.

function pushelement() public {
    by1 = abi.encodePacked(by1, bytes1(0x10));
}
Related